package com.bluesky.dreamer.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bluesky.dreamer.common.CommandFactory;
import com.bluesky.dreamer.common.HttpCommand;
import com.sitech.biportal.util.NumberUtil;


public class CommandServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		HttpCommand cmd = null;
		String cmdStr = request.getParameter("cmd");
		
		if (cmdStr == null)
			cmdStr = "0";
		else
			cmdStr = cmdStr.trim();
		
		if (cmdStr.matches("\\d+"))
			cmd = CommandFactory.getHttpCommand(NumberUtil.toInt(cmdStr));
		else {
			cmd = CommandFactory.getHttpCommand(cmdStr);
		}
		cmd.setHttpServletRequest(request);
		cmd.setHttpServletResponse(response);
		cmd.process(null);
	}

}
